package cn.yuanqiao.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.domain.R;
import cn.yuanqiao.common.utils.SecurityUtils;
import cn.yuanqiao.common.utils.SnowflakeIdGenerator;
import cn.yuanqiao.feignService.RemoteCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import cn.yuanqiao.system.domain.SysNotice;
import cn.yuanqiao.system.mapper.SysNoticeMapper;
import cn.yuanqiao.system.service.ISysNoticeService;

/**
 * 公告 服务层实现
 *
 * @author ruoyi
 */
@Service
public class SysNoticeServiceImpl implements ISysNoticeService
{
    @Autowired
    private SysNoticeMapper noticeMapper;
    @Autowired
    RemoteCommonService remoteCommonService;
    @Value("${FBswitch}")
    private boolean FBswitch;

    /**
     * 查询公告信息
     *
     * @param noticeId 公告ID
     * @return 公告信息
     */
    @Override
    public SysNotice selectNoticeById(Long noticeId)
    {
        return noticeMapper.selectNoticeById(noticeId);
    }

    /**
     * 查询公告列表
     *
     * @param notice 公告信息
     * @return 公告集合
     */
    @Override
    public List<SysNotice> selectNoticeList(SysNotice notice)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        notice.setTenantCode(tenantCode);
        if(FBswitch){
            R<AjaxResult> getdamjbyrymjforsys = remoteCommonService.getdamjbyrymjforsys();
            List<Map<String,String>> listmap= (List<Map<String,String>>)getdamjbyrymjforsys.getData().get("data");
            List<String> list=new ArrayList<String>(listmap.size());
            for (int i = 0; i < listmap.size(); i++) {
                list.add("'"+listmap.get(i).get("DA_MJ")+"'");
            }
            notice.setMiJi(list.toString().replace("[","").replace("]",""));
        }
        return noticeMapper.selectNoticeList(notice);
    }

    /**
     * 新增公告
     *
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int insertNotice(SysNotice notice)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        notice.setTenantCode(tenantCode);
        return noticeMapper.insertNotice(notice);
    }

    /**
     * 修改公告
     *
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int updateNotice(SysNotice notice)
    {
        return noticeMapper.updateNotice(notice);
    }

    /**
     * 删除公告对象
     *
     * @param noticeId 公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeById(Long noticeId)
    {
        return noticeMapper.deleteNoticeById(noticeId);
    }

    /**
     * 批量删除公告信息
     *
     * @param noticeIds 需要删除的公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeByIds(Long[] noticeIds)
    {
        return noticeMapper.deleteNoticeByIds(noticeIds);
    }

    @Override
    public List<SysNotice> selectNoticeListYs(SysNotice notice) {
        String tenantCode = SecurityUtils.getTenantCode();
        notice.setTenantCode(tenantCode);
        return noticeMapper.selectNoticeListYs(notice);
    }
}
